/**
 * Copyright 2015 - 2016 KeepSafe Software, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.getkeepsafe.relinker;

import ohos.app.Context;

import java.io.File;

/**
 *ReLinker is a small library to help alleviate {@link UnsatisfiedLinkError} exceptions thrown due
 *to loading of native libraries for previous versions.
 */
public class ReLinker {
    /**
     * Function description
     * interface LoadListener
     */
    public interface LoadListener {
        /**
         * method success
         *
         */
        void success();

        /**
         * method failure
         *
         * @param throwFailure Throwable
         */
        void failure(Throwable throwFailure);
    }
    /**
     * Constructor ReLinker
     *

     */
    private ReLinker() { }

    /**
     * Function description
     * interface Logger
     */
    public interface Logger {
        /**
         * method log
         *
         * @param message string
         *
         */
        void log(String message);
    }

    /**
     * Function description
     * interface ReLinker
     */
    public interface LibraryLoader {
        /**
         * method log
         *
         * @param libraryName string
         *
         */
        void loadLibrary(String libraryName);
        /**
         * method loadPath
         *
         * @param libraryPath string
         *
         */

        void loadPath(String libraryPath);

        /**
         * method mapLibraryName
         *
         * @param libraryName string
         * @return String
         */
        String mapLibraryName(String libraryName);

        /**
         * method unmapLibraryName
         *
         * @param mappedLibraryName string
         * @return string
         */
        String unmapLibraryName(String mappedLibraryName);

        /**
         * method supportedAbis
         *
         * @return String
         */
        String[] supportedAbis();
    }

    /**
     * Function description
     * interface LibraryInstaller
     */
    public interface LibraryInstaller {
        /**
         * method installLibrary
         *
         * @param context Context
         * @param abis String[]
         * @param mappedLibraryName String
         * @param destination File
         * @param logger ReLinkerInstance
         *
         */
        void installLibrary(Context context, String[] abis, String mappedLibraryName, File destination,
                            ReLinkerInstance logger);
    }

    /**
     * method loadLibrary
     *
     * @param context Context
     * @param library String
     * *@return loadLibrary(context, library, null, listener)
     *
     */
    public static void loadLibrary(final Context context, final String library) {
        loadLibrary(context, library, null, null);
    }

    /**
     * method loadLibrary
     *
     * @param context Context
     * @param library String
     * @param version String
     *
     */
    public static void loadLibrary(final Context context, final String library, final String version) {
        /**
         * method loadLibrary
         *
         *
         */
        loadLibrary(context, library, version, null);
    }

    /**
     * method loadLibrary
     *
     * @param context Context
     * @param library String
     * @param listener LoadListener
     * *@return loadLibrary(context, library, null, listener)
     *
     */
    public static void loadLibrary(final Context context, final String library, final LoadListener listener) {
        loadLibrary(context, library, null, listener);
    }

    /**
     * method loadLibrary
     *
     * @param context Context
     * @param library String
     * @param version String
     * @param listener ReLinker.LoadListener
     *
     * * @return new ReLinkerInstance().loadLibrary(context, library, version, listener)
     */
    public static void loadLibrary(final Context context,
                            final String library,
                            final String version,
                            final LoadListener listener) {
        new ReLinkerInstance().loadLibrary(context, library, version, listener);
    }

    /**
     * method ReLinkerInstance force
     *
     * @return ReLinkerInstance.log()
     */
    public static ReLinkerInstance force() {
        return new ReLinkerInstance().force();
    }

    /**
     * method ReLinkerInstance instance
     *
     * @param logger Logger
     * @return ReLinkerInstance.log()
     */
    public static ReLinkerInstance log(final Logger logger) {
        return new ReLinkerInstance().logDetails(logger);
    }

    /**
     * method recursively instance
     *
     * @return ReLinkerInstance.recursively()
     *
     */
    public static ReLinkerInstance recursively() {
        return new ReLinkerInstance().recursively();
    }
}
